package iut.acy.cut4u.model;



import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Locale;

public class FormatDate {
	
	public static String format ="JJ/MM/AAAA";

	 public static DateFormat formatDate = new SimpleDateFormat("dd/MM/yyyy");
	 
	 public static String gregorianToString(GregorianCalendar gdate)
	{
		String str =FormatDate.formatDate.format(gdate.getTime());
		return str;
	}
	 
	 
	 public static GregorianCalendar stringToGregorianCalendar(String sdate)
		{
	      if ( sdate ==null)
	    	  return null;
	      if( sdate.equals(""))
	    	  return null;
	    
	      GregorianCalendar gdate =new GregorianCalendar();
	     boolean dateOK= false ;
	     Date date;
	      try {
		    date = FormatDate.formatDate.parse(sdate);
		    gdate.setTime(date);
		    dateOK = true ;
	       } catch (ParseException e) {
		
		System.out.println (e);
            	}
	       if ( dateOK ==true)
	    	   return gdate;
	    	else
	    		return null;
		}
	       
}
